[Android] GPS can't run inside TimerTask

Posted by user568553 on Stack Overflow See other posts from Stack Overflow or by user568553
Published on 2011-01-09T04:46:53Z Indexed on 2011/01/09 4:54 UTC
Read the original article Hit count: 196

Filed under:
|
|

Hi,

I am trying to write an android app that acquires a GPS signal at a fix time interval, for example every 1 minute. Since the requestLocationUpdate function does not exactly implement that, I tried to use task to accomplished it.

public class getGPS extends TimerTask{
     public void run(){
        System.out.println("Running a GPS task");
        locHandler = new locationUpdateHandler();    


        myManager.requestLocationUpdates(provider, 60000, 0, locHandler);


     }
 }


public void LoadCoords(){

     Timer timer = new Timer();
     timer.scheduleAtFixedRate(new getGPS(), 0, 60000);
}

However, from what I've seen, requestLocationUpdates would run fine if I put it inside LoadCoords(), but would not run if I put it inside the TimerTask (ie no green icon on the task bar to show that GPS is looking for a fix).

Can anyone please suggest an alternative approach or pseudo-code, or correct my mistake if there is one ? Thank you in advance.

© Stack Overflow or respective owner

Related posts about android

Related posts about gps